package com.nali.dal.statement.function.formatter.date;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.nali.dal.statement.function.AbstractDataHandler;
import com.nali.dal.statement.function.FunctionArgument;
import com.nali.dal.statement.function.FunctionException;

@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class Now extends AbstractDataHandler<Date> {
	private Date date=new Date();

	@Override
	public Date handle(List<Object> argList) throws FunctionException {
		TimeUnit timeUnit;
		if(argList.size()==1) {
			timeUnit = TimeUnit.getTimeUnit((String) argList.get(0));
		} else {
			timeUnit = TimeUnit.MILLSECOND;
		}
		return timeUnit.convert(date);
	}

	@Override
	public void validate(List<FunctionArgument> arguments) throws FunctionException {
		checkSize(arguments, 0, 1);
	}
}

